/*  _________________________________________
   /                                      /_ \
  |             Player HUD               |/ \ |
  |                                      |___||
   \______________________________________\_/ |
       |                                      |
      /     Player H.U.D. Environment		 /
     /     Written April, 2009				/
    |     by Darrell Eastman.              |___
    |                                      |   |
     \______________________________________\_/
*/

class HUD
{
public:
	HUD( user, stringw )
	{
		/*////////////////////////// Client Attribute //////////////////////////
		//Amm, Hth, WpnInf, EqpInf, AphInd, ActTmr, ActAcc, Eqp	
		//stringw	GamSte	= "Introduction";	//Current GameState
		//stringw  	Nam		= "HondaDarrell";	//Name of Player
		//stringw  	Cla		= "Pirate";			//Skill of Player
		//stringw		Inv[][]	=					//Player Iventory Key, Scroll
		//	{{"Key"}, {"Treasure"}};
		int			Amm[]	=					//Weapon Select
			//Ammo|Round| Item| Current Weapon
			{ 1000, 0005, 1000, 00 };
		int			Eqp[]	= { 2, 0 };			//Equipment Select
		float		Hth		=					//Health PercentagE
			Usr.Hth() / 1000 * 100;
		ISceneNode	Tgt		= Usr;				//Current Target
		vector3df	TgtRot	=					//Last Target Rotation
			Usr.Nde.getRotation();
		float		ActTmr[3];					//Rate Timer Action Pri | Action Sec, Round Timer Action Pri
		float		ActAcc[2];					//Accuracy Percentage, Action Pri | Action Sec
		float		AphInd[3];					//Change Indication, Ammo Change | Items Change | Health Change*/
	};

	Update()
	{
		//Use Rate
		if( ActTmr[0] > NULL || ActTmr[1] > NULL )
		{
			//Weapon Rate
			if( ActTmr[0] > NULL )
				ActTmr[0] -= 1000 / LastFPS;	//Subtract 1 Millisecond

			//Item Rate
			if( ActTmr[1] > NULL )
				ActTmr[1] -= 1000 / LastFPS;	//Subtract 1 Millisecond
		}

		//Rounds
		if( ActTmr[2] > NULL && ActTmr[0] =< NULL )
		{
			//Draw Weapon Round Reload
			driver.draw2DImageSegment( TmrIcn, position2di<s32>( 64, 640 ),
				rect<s32>( 0, 0, 64, 64 / double( int( WpnInf[Eqp[Amm[3]]][2] ) * ActTmr[Amm[3] + 2] )), NULL,
				SColor( 255, 255, 255, 255 ), true );

			//Weapon Reload
			if( ActTmr[2] > NULL )
				ActTmr[2] -= 1000 / LastFPS;	//Subtract 1 Millisecond
		}

		//Reload Rounds
		if( WpnInf[Eqp[0]][4] && Amm[0] > NULL && Amm[1] =< NULL && ActTmr[2] =< NULL )
		{
			ActTmr[2]	= int( WpnInf[Eqp[0]][2] );
			//Reload Rounds From Remaining Ammo
			Amm[1]		= int( WpnInf[Eqp[0]][4] );
			//Subtract Rounds From Ammo
			Amm[0]		-= int( WpnInf[Eqp[0]][4] );
			AphInd[0]	= 100;
			AphInd[1]	= 100;
		}
		else
		if( ActTmr[2] > NULL )
			ActTmr[2] -= float( 1000 / LastFPS );	//Subtract 1 Millisecond

		/*
		Accuracy Decay
		if( ActAcc[0] > 0 )
			ActAcc[0] -= Projectile.PrjInf[Eqp[0]][6]; 'Subtract Accuracy
		else
			ActAcc[0] = 0;

		if( ActAcc[1] > 0 )
			ActAcc[1] -= Projectile.PrjInf[Eqp[1]][6]; 'Subtract Accuracy
		else
			ActAcc[1] = 0;
		*/
	};

	Blink()
	{
		//Indicators
		int	T	= 1000;	//Fade in Milliseconds

		//Ammo Change Indication
		if( AphInd[0] > NULL )
			AphInd[0] -= 100 / ( T / LastFPS );
		else if( AphInd[0] < NULL )
			AphInd[0] = 0;

		//Round Change Indication
		if( AphInd[1] > NULL )
			AphInd[1] -= 100 / ( T / LastFPS );
		else if( AphInd[1] < NULL )
			AphInd[1] = 0;

		//Hth Change Indication
		if( AphInd[2] > NULL )
			AphInd[2] -= 100 / ( T / LastFPS );
		else if( AphInd[2] < NULL )
			AphInd[2] = 0;
	};

	drawAll()
	{
		//Primary
		if( Amm[3] == NULL )
		//Draw Weapon
			driver->draw2DImageSegment( WpnIcn, position2di<s32>( 64, 640 ),
				rect<s32>( Eqp[0] * 64, 0, 64 + ( Eqp[0] * 64 ), 64 ), NULL,
				SColor( 255, 255, 255, 255 ), true );

		else if( Amm[3] = 1 )
		//Draw Item
			driver->draw2DImageSegment( ItmIcn, position2di<s32>( 64, 640 ),
				rect<s32>( Eqp[1] * 64, 0, 64 + ( Eqp[1] * 64 ), 64 ), NULL,
				SColor( 255, 255, 255, 255 ), true );

		//Primary Rounds
		if( Amm[3] == NULL )
		{
			//Draw Rounds Glow
			if( AphInd[1] > NULL )
				HUDGlow.Draw( Amm[1],
					rect<s32>( 64, 640 - 16, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( int(( 255 / 100 ) * AphInd[1] ), 0, 255, 0 ));

			//Draw Rounds
			if( WpnInf[Eqp[0]][4] )
				HUDFont->Draw( Amm[1],
					rect<s32>( 64, 640 - 16, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( 255, int(( 127 / 100 ) * AphInd[1] ), 191 + int(( 64 / 100 ) * AphInd[1] ), int(( 127 / 100 ) * AphInd[1] )));
		}

		//* Incomplete, need to reposition text	//Draw Ammo
		if( Amm[3] == NULL && WpnInf[Eqp[0]][3] )
		{
			//Weapon, Capacity Not NULL
			if( AphInd[0] > NULL )
			{
				//Draw Ammo Glow
				HUDGlow.Draw( Amm[0],
					rect<s32>( 64, 640, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( int(( 255 / 100 ) * AphInd[0] ), 0, 255, 0 ));

				//Draw Ammo
				HUDFont.Draw( Amm[0],
					rect<s32>( 64, 640, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( 255, int(( 127 / 100 ) * AphInd[0] ), 191 + int(( 64 / 100 ) * AphInd[0] ), int(( 127 / 100 ) * AphInd[0] )));
			}
		}

		else
		if( Amm[3] = 1 && EqpInf[Eqp[1]][2] )
		{
			//Item, Capacity Not NULL
			if( AphInd[0] > NULL )
			{
				//Draw Ammo Glow
				HUDGlow.Draw( Amm[2],
					rect<s32>( 64, 640, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( int(( 255 / 100 ) * AphInd[0] ), 0,
									   255, 0 ));

				//Draw Ammo
				HUDFont.Draw( Amm[2],
					rect<s32>( 64, 640, 64 + ( 5 * 18 ), 640 + ( 28 / 2 )),
					SColor( 255, int(( 127 / 100 ) * AphInd[0] ), 191 + int(( 64 / 100 ) * AphInd[0] ), int(( 127 / 100 ) * AphInd[0] )));
			}
		}
		//Secondary
		//Draw Item
		driver.draw2DImageSegment( ItemIcon, position2di<s32>( 32, 704 ),
			rect<s32>( 32 * Gadgets[1][0], 0, 32 + ( 32 * Gadgets[1][0] ), 32 ),
			NULL,
			SColor( 255, 255, 255, 255 ), true );

		//Draw Gadgets
		if( AlphaIndication[1] > NULL )
			HUDGlow.Draw( Items[0][Items[1][0]],
				rect<s32>( 64, 704, 64 + ( 5 * 18 ), 704 + ( 28 / 2 )),
				SColor( int(( 255 / 100 ) * AlphaIndication[1] ), 0, 255, 0 ));
		HUDFont.Draw( Items[0][Items[1][0]],
			rect<s32>( 64, 704, 64 + ( 5 * 18 ), 704 + ( 28 / 2 )),
			SColor( 255, int(( 127 / 100 ) * AlphaIndication[1] ), 191 + int(( 64 / 100 ) * AlphaIndication[1] ), int(( 127 / 100 ) * AlphaIndication[1] )));
	};

	~HUD();

private:
	////////////////// Info HUD ///////////////////
		//    Name|   Rate| Reload|    Max| Round| Damage|   Ammo|Report
		//        |    Ms.|    Ms.|       |      |    Hp.|     ID|Radius
	const stringw	WpnInf[][]	=					//Weapon Info Table
		{{"Swd"   ,  "500",  "500",     "",    "",   "15",     "",    ""},
		{ "Stf"   , "1500", "1500",     "",    "",   "20",     "",    ""},
		{ "NunChk",  "150",  "150",     "",    "",    "5",     "",    ""},
		{ "ThrStr",  "500", "2000",   "25",   "5",    "5",    "1",    ""},
		{ "ThrKnf", "1000", "1500",   "15",   "2",   "10",    "2",    ""}};
		//    Name| Reload|   Max|    Life|Damage|Report|   Ammo| ?
		//        |   /Ms.|      |     Ms.|   Hp.|Radius|     ID| ?
	const stringw	EqpInf[][]	=					//Item Info Table
		{{"GrpHok",     "",    "",     "0", "000",    "",    "2",  "1"},
		{ "ZipLin",     "",    "",    "-1", "000",    "",    "3",  "3"},
		{ "LokPik",     "",    "",    "-1", "000",   "5",     "",   ""},
		{ "SmkBmb", ".025",   "5", "15000", "000", "100",     "",   ""},
		{ "GasBmb", ".025",   "5", "10000", "003",  "80",     "",   ""}};
	const ITexture	WpnIcn		=					//Weapon Icon Image
		driver.getTexture( "media/Weapon.tga" );
	const ITexture	ItmIcn		=					//Item Icon Image
		driver.getTexture( "media/Item.tga" );
	const ITexture	TmrIcn		=					//Reload Overlay Image
		driver.getTexture( "media/Timer.tga" );
	//ITexture		StsBar		=					//Status Bar Outline
		//driver.getTexture( "media/StatusBar.tga" )
	//ITexture		Sts			=					//Status Bar Image
		//driver.getTexture( "media/Status.tga" )
};

HUD::HUD( user Usr, stringw GmeSte )
{
	////////////////////////// Client Attribute //////////////////////////
	//Amm, Hth, WpnInf, EqpInf, AphInd, ActTmr, ActAcc, Eqp	
	//stringw	GamSte	= "Introduction";	//Current GameState
	//stringw  	Nam		= "HondaDarrell";	//Name of Player
	//stringw  	Cla		= "Pirate";			//Skill of Player
	//stringw		Inv[][]	=					//Player Iventory Key, Scroll
	//	{{"Key"}, {"Treasure"}};
	int			Amm[]	=					//Weapon Select
		//Ammo|Round| Item| Current Weapon
		{ 1000, 0005, 1000, 00 };
	int			Eqp[]	= { 2, 0 };			//Equipment Select
	float		Hth		=					//Health PercentagE
		Usr.Hth() / 1000 * 100;
	ISceneNode	Tgt		= Usr;				//Current Target
	vector3df	TgtRot	=					//Last Target Rotation
		Usr.Nde.getRotation();
	float		ActTmr[3];					//Rate Timer Action Pri | Action Sec, Round Timer Action Pri
	float		ActAcc[2];					//Accuracy Percentage, Action Pri | Action Sec
	float		AphInd[3];					//Change Indication, Ammo Change | Items Change | Health Change
};

HUD::~HUD()
{
};